﻿using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Display;
using System.IO;

namespace WatchDog.WinService;

/// <summary>
/// 自定义日志接收器，实现将日志发送到客户端UI中
/// </summary>
public class SendLogToClientSink : ILogEventSink
{
    readonly ITextFormatter _textFormatter = new MessageTemplateTextFormatter("{Timestamp} [{Level}] {Message}{Exception}");

    public void Emit(LogEvent logEvent)
    {
        if (logEvent != null)
        {
            var renderSpace = new StringWriter();
            _textFormatter.Format(logEvent, renderSpace);

            //SendLogToClientService.SendChannel.Writer.TryWrite(renderSpace.ToString());
        }
    }

}
